﻿@Imports System.Collections.ObjectModel
@imports Library

@Code        
    ViewData("Title") = "Index"
    
    Dim IASummary As list(Of MonthlySummary) = MonthlySummary.FindByOwner("IA")
    Dim VincentSummary As List(Of MonthlySummary) = MonthlySummary.FindByOwner("VINCENT")
    Dim NicoleSummary As list(Of MonthlySummary) = MonthlySummary.FindByOwner("NICOLE")
    
    Dim JsonData As String = ""
    If IASummary.Count > 0 Then
        For Each item As MonthlySummary In IASummary
            JsonData += "[new Date(" + item.Month.Substring(0, 4) + "," + item.Month.Substring(5, 2) + ")," + item.Spend.ToString("G0") + ",null,null," +
                item.Income.ToString("G0") + ",null,null," + item.Profit.ToString("G0") + ",null,null],"
        Next
        JsonData = JsonData.Substring(0, JsonData.Length() - 1)
    Else
        JsonData = "NoData"
    End If
    
    Dim JsonDataVincent As String = ""
    If VincentSummary.Count > 0 Then
        For Each item As MonthlySummary In VincentSummary
            JsonDataVincent += "[new Date(" + item.Month.Substring(0, 4) + "," + item.Month.Substring(5, 2) + ")," + item.Spend.ToString("G0") + ",null,null," +
                item.Income.ToString("G0") + ",null,null," + item.Profit.ToString("G0") + ",null,null],"
        Next
        JsonDataVincent = JsonDataVincent.Substring(0, JsonDataVincent.Length() - 1)
    Else
        JsonDataVincent = "NoData"
    End If
    
    Dim JsonDataNicole As String = ""
    If NicoleSummary.Count > 0 Then
        For Each item As MonthlySummary In NicoleSummary
            JsonDataNicole += "[new Date(" + item.Month.Substring(0, 4) + "," + item.Month.Substring(5, 2) + ")," + item.Spend.ToString("G0") + ",null,null," +
                item.Income.ToString("G0") + ",null,null," + item.Profit.ToString("G0") + ",null,null],"
        Next
        JsonDataNicole = JsonDataNicole.Substring(0, JsonDataNicole.Length() - 1)
    Else
        JsonDataNicole = "NoData"
    End If
    
End Code

<div id="page">

    <div id="page_header" class="no_bottom">
        <h3>Month Summary</h3>
    </div>

    <div id="page_body">

        <div id="tabs">

	        <ul>
                <li><a href="#TabIA">IA Account</a></li>
                <li><a href="#TabVINCENT">VINCENT</a></li>
                <li><a href="#TabNICOLE">NICOLE</a></li>
	        </ul>
            
            <div class="cls"></div>

            <div class="IE_padding_hack">
	
                <div id="TabIA">
                    
                    <div class="total">
                        Total Amount:  <span class="red">@IASummary.ToList.Sum(Function(item) item.Profit)</span> &nbsp;
                        Without This Month <span class="green">@IASummary.where(Function(item) item.Month<>Now.ToString("yyyy-MM")).ToList.Sum(Function(item) item.Profit)</span>
                    </div>

                    @Html.Hidden("JsonAllData", jsonData)
		            <div id="visualization" style="width: 100%; height: 400px;"></div>

                    <div style="margin:30px 0 15px 0;">Last 5 month Records</div>

	                <table class="display">
		                <tr><th>Action</th><th>Month</th><th>Spend</th><th>Income</th><th>Profit</th></tr>
                        @If IASummary.Count <> 0 Then
                            For Each item As MonthlySummary In IASummary.Take(5)
                                @<tr>
                                    <td>@Html.ActionLink("Edit", "edit", "MonthlySummary", new With{.id = item.Id}, nothing)</td>
	                                <td>@item.Month</td><td>@item.Spend.ToString</td>
	                                <td>@item.Income.ToString</td><td>@item.Profit.ToString</td>  
                                </tr>
                            Next
                        Else
                            @<tr><td colspan="5">No Data Now.</td></tr>
                        End If
	                </table>
                </div>
    
                <div id="TabVINCENT">
                    
                    <div class="total">
                        Total Amount:  <span class="red">@VincentSummary.ToList.Sum(Function(item) item.Profit)</span> &nbsp;
                        Without This Month <span class="green">@VincentSummary.where(Function(item) item.Month<>Now.ToString("yyyy-MM")).ToList.Sum(Function(item) item.Profit)</span>
                    </div>

                    @Html.Hidden("JsonAllDataVincent", jsonDataVincent)
		            <div id="visualizationVincent" style="width: 100%; height: 400px;"></div>

                    <div style="margin:30px 0 15px 0;">Last 5 month Records</div>

	                <table class="display">
		                <tr><th>Action</th><th>Month</th><th>Spend</th><th>Income</th><th>Profit</th></tr>
                        @If IASummary.Count <> 0 Then
                            For Each item As MonthlySummary In VincentSummary.Take(5)
                                @<tr>
                                    <td>@Html.ActionLink("Edit", "edit", "MonthlySummary", new With{.id = item.Id}, nothing)</td>
	                                <td>@item.Month</td><td>@item.Spend.ToString</td>
	                                <td>@item.Income.ToString</td><td>@item.Profit.ToString</td>  
                                </tr>
                            Next
                        Else
                            @<tr><td colspan="5">No Data Now.</td></tr>
                        End If
	                </table>
                </div>
    
                <div id="TabNICOLE">
                    
                    <div class="total">
                        Total Amount:  <span class="red">@NicoleSummary.ToList.Sum(Function(item) item.Profit)</span> &nbsp;
                        Without This Month <span class="green">@NicoleSummary.where(Function(item) item.Month<>Now.ToString("yyyy-MM")).ToList.Sum(Function(item) item.Profit)</span>
                    </div>

                    @Html.Hidden("JsonAllDataNicole", jsonDataNicole)
		            <div id="visualizationNicole" style="width: 100%; height: 400px;"></div>

                    <div style="margin:30px 0 15px 0;">Last 5 month Records</div>

	                <table class="display">
		                <tr><th>Action</th><th>Month</th><th>Spend</th><th>Income</th><th>Profit</th></tr>
                        @If IASummary.Count <> 0 Then
                            For Each item As MonthlySummary In NicoleSummary.Take(5)
                                @<tr>
                                    <td>@Html.ActionLink("Edit", "edit", "MonthlySummary", new With{.id = item.Id}, nothing)</td>
	                                <td>@item.Month</td><td>@item.Spend.ToString</td>
	                                <td>@item.Income.ToString</td><td>@item.Profit.ToString</td>  
                                </tr>
                            Next
                        Else
                            @<tr><td colspan="5">No Data Now.</td></tr>
                        End If
	                </table>
                </div>

            </div>

        </div>
            
        <div class="cls"></div>
                    
    </div>
        
</div>
    
@section Scripts

<script type="text/javascript" src="http://www.google.com/jsapi"></script>
<script type="text/javascript">
	
    google.load('visualization', '1', {packages: ['annotatedtimeline']});
    
    function drawVisualization() {

        if ($("#JsonAllData").val() != "NoData") {
            var data = new google.visualization.DataTable();
            data.addColumn('date', 'Date');
            data.addColumn('number', 'Spend');
            data.addColumn('string', 'title1');
            data.addColumn('string', 'text1');
            data.addColumn('number', 'Income');
            data.addColumn('string', 'title2');
            data.addColumn('string', 'text2');
            data.addColumn('number', 'Profit');
            data.addColumn('string', 'title3');
            data.addColumn('string', 'text3');
            data.addRows(eval('[' + $("#JsonAllData").val() + ']'));
            var annotatedtimeline = new google.visualization.AnnotatedTimeLine(document.getElementById('visualization'));
            annotatedtimeline.draw(data, { 'displayAnnotations': true });
        }

        if ($("#JsonAllDataVincent").val() != "NoData") {
            var dataVincent = new google.visualization.DataTable();
            dataVincent.addColumn('date', 'Date');
            dataVincent.addColumn('number', 'Spend');
            dataVincent.addColumn('string', 'title1');
            dataVincent.addColumn('string', 'text1');
            dataVincent.addColumn('number', 'Income');
            dataVincent.addColumn('string', 'title2');
            dataVincent.addColumn('string', 'text2');
            dataVincent.addColumn('number', 'Profit');
            dataVincent.addColumn('string', 'title3');
            dataVincent.addColumn('string', 'text3');
            dataVincent.addRows(eval('[' + $("#JsonAllDataVincent").val() + ']'));
            var annotatedtimelineVincent = new google.visualization.AnnotatedTimeLine(document.getElementById('visualizationVincent'));
            annotatedtimelineVincent.draw(dataVincent, { 'displayAnnotations': true });
        }

        if ($("#JsonAllDataNicole").val() != "NoData") {
            var dataNicole = new google.visualization.DataTable();
            dataNicole.addColumn('date', 'Date');
            dataNicole.addColumn('number', 'Spend');
            dataNicole.addColumn('string', 'title1');
            dataNicole.addColumn('string', 'text1');
            dataNicole.addColumn('number', 'Income');
            dataNicole.addColumn('string', 'title2');
            dataNicole.addColumn('string', 'text2');
            dataNicole.addColumn('number', 'Profit');
            dataNicole.addColumn('string', 'title3');
            dataNicole.addColumn('string', 'text3');
            dataNicole.addRows(eval('[' + $("#JsonAllDataNicole").val() + ']'));
            var annotatedtimelineNicole = new google.visualization.AnnotatedTimeLine(document.getElementById('visualizationNicole'));
            annotatedtimelineNicole.draw(dataNicole, { 'displayAnnotations': true });
            
            $("#tabs").tabs();
        }
	}
	
	google.setOnLoadCallback(drawVisualization);

	$(function () {
	    $("#global_nav li a").eq(3).addClass("selected");
	});
</script>

End Section